|
|
 |
|
|
|
|
G = G + light.Ig * DiffuseKg * diffuse_factor
B = B + light.Ib * DiffuseKb * diffuse_factor
' ***********************
' * Specular Reflection *
' ***********************
' Find the unit vector V from the surface
' to the viewing position. Vx = eye_x - Points(1).coord(1)
Vy = eye_y - Points(1).coord(2)
Vz = eye_z - Points(1).coord(3)
V_len = Sqr(Vx * Vx + Vy * Vy + Vz * Vz)
Vx = Vx / V_len
Vy = Vy / V_len
Vz = Vz / V_len
' Find the mirror vector R. Rx = 2 * Nx * NdotL - Lx
Ry = 2 * Ny * NdotL - Ly
Rz = 2 * Nz * NdotL - Lz
' Calculate the specular component. RdotV = Rx * Vx + Ry * Vy + Rz * Vz
specular_factor = SpecularK * (RdotV ^ SpecularN)
R = R + light.Ir * specular_factor
G = G + light.Ig * specular_factor
B = B + light.Ib * specular_factor
End If ' End if NdotL > 0 . . . Next light
' Add the ambient term. R = R + ambient_light * AmbientKr
G = G + ambient_light * AmbientKg
B = B + ambient_light * AmbientKb
' Keep the color components <= 255. If R > 255 Then R = 255
If G > 255 Then G = 255
If B > 255 Then B = 255
' Return the color. SurfaceColor = RGB(R, G, B)
End Function |
|
|
|
|
|
|
|
|
Example program Light4, shown in Figures 16.10 and 16.11, uses this method to display three-dimensional objects. In both Figures 16.10 and 16.11, the constant ks in the equation ks * (R V)n was 0.5. The constant n was 10 in Figure 16.10 and 100 in Figure 16.11. Larger values for n give smaller highlights. |
|
|
|
|
|
|
|
|
You may recall that the lighting model ignores several of the more complicated aspects of the physics of lighting. For instance, the ambient term does not take into account |
|
|
|
|
|